define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'jdy/smallcategory/index',
                    add_url: 'jdy/smallcategory/add',
                    edit_url: 'jdy/smallcategory/edit',
                    del_url: 'jdy/smallcategory/del',
                    multi_url: 'jdy/smallcategory/multi',
                    table: 'jdy_smallcategory',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showColumns: true,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        //{field: 'id', title: __('Id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate},
                        //{field: 'bigcategory_id', title: __('Bigcategory_id')},
                        {field: 'bigcategory.name', title: __('大類別名稱'), operate:false},
                        //{field: 'type', title: __('大類別名稱'), operate:false},
                        {field: 'name', title: __('Name'), operate: 'LIKE %...%', placeholder: '模糊搜索，*表示任意字符'},
                        {field: 'alias', title: __('Alias'), operate:false},
                        //{field: 'ignore_duration_time', title: __('Ignore_duration_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), searchList: {"0":__('不啟用'),"1":__('啟用')}, formatter: Table.api.formatter.status},
                        {field: 'opman', title: __('Opman'), operate:false},
                        //{field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'bigcategory.id', title: __('Bigcategory.id')},
                        //{field: 'bigcategory.type', title: __('Bigcategory.type')},
                        //{field: 'bigcategory.name', title: __('Bigcategory.name')},
                        //{field: 'bigcategory.status', title: __('Bigcategory.status')},
                        //{field: 'bigcategory.opman', title: __('Bigcategory.opman')},
                        //{field: 'bigcategory.create_time', title: __('Bigcategory.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'bigcategory.update_time', title: __('Bigcategory.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},

                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});